home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / rexx / cmdshell.quill < prev    next >
Text File  |  1995-08-29  |  3KB  |  102 lines

  1.  
  2. /**
  3.  **  $VER: CmdShell.quill 1.1 (27.9.94)
  4.  **
  5.  **  CmdShell.quill - Command shell for Digital Quill
  6.  **      Make sure this file is in your REXX: directory and that it is
  7.  **      called "CmdShell.quill" (without the quotes) otherwise the editor
  8.  **      will NOT be able to start the command shell!
  9.  **
  10.  **      This macro implements the command line shell for the editor.  This
  11.  **      is a command-line interface for Digital Quill, a means of entering
  12.  **      editor commands from the keyboard.  This is implemented through
  13.  **      ARexx to obtain maximum power and flexibility.  Everything you
  14.  **      enter in the command shell window is actual a line of ARexx code,
  15.  **      so all ARexx commands, functions, and contructs are available to
  16.  **      you, in addition to the host of editor specific commands.
  17.  **
  18.  **/
  19.  
  20.  
  21. /* Some setup first.
  22.  */
  23. options results
  24. options failat 100
  25.  
  26. prompt = address()'> '
  27.  
  28. /* Get the rexxsupport.library.
  29.  */
  30. if ~show(l, "rexxsupport.library") then
  31.     if ~addlib("rexxsupport.library", 0, -30) then
  32.         exit
  33.  
  34. /* Here's where the actual macro begins.
  35.  */
  36. main:
  37.     /* Open the output window.
  38.      */
  39.     'GETATTR' 'WINDOW STEM' window_attrs
  40.     'GETATTR' 'APPLICATION SCREEN VAR' screenname
  41.  
  42.     winleft = window_attrs.borderleft + window_attrs.left
  43.     winwidth = 500
  44.     winheight = 80
  45.     wintop = window_attrs.top + window_attrs.bordertop
  46.     window_parm = 'CON:'winleft'/'wintop'/'winwidth'/'winheight'/Command Shell/CLOSE/AUTO/SCREEN'||screenname''
  47.  
  48.     if open('window_fh', window_parm, 'R') then do
  49.         /* Loop around continuously getting input from the user.  This works
  50.          * very similarly to a standard AmigaDOS shell, users type in commands
  51.          * followed by <Return>.  Basically, we'll just pass whatever is
  52.          * entered onto ARexx, except for some special case commands for help,
  53.          * changing the command prompt, and exiting the shell.
  54.          */
  55.         do forever
  56.             /* Prompt.
  57.              */
  58.             call writech('window_fh', prompt)
  59.  
  60.             /* Wait until the user types a command followed by RETURN
  61.              */
  62.             cmd = readln('window_fh')
  63.  
  64.             select
  65.                 when (cmd = "") | (upper(cmd) = "ENDSHELL") then
  66.                     leave
  67.  
  68.                 when (cmd = "?") | (upper(cmd) = "HELP") then do
  69.                     call writeln('window_fh', 'Enter "HELP <command>" to obtain a command''s template.')
  70.                     call writeln('window_fh', 'Press <Ctrl>\ or enter "ENDSHELL" to close the shell.')
  71.                 end
  72.  
  73.                 otherwise call handle_cmd(cmd)
  74.             end
  75.         end
  76.  
  77.         call writeln('window_fh', 'Done.')
  78.     end
  79.  
  80.     return
  81.  
  82.  
  83. /* Handle the command entered by the user.
  84.  */
  85. handle_cmd: procedure
  86.     parse arg cmd
  87.  
  88.     /* Execute the command through ARexx itself.
  89.      */
  90.     interpret cmd
  91.  
  92.     /* See if the command succeeded and display and result string.
  93.      */
  94.     if rc = 0 then do
  95.         if symbol('RESULT') == "VAR" then do
  96.             call writeln('window_fh', result)
  97.         end
  98.         return
  99.     end
  100.  
  101.     return
  102.